/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.citi.dahg.cve;

import com.citi.dahg.cve.controller.exceptions.SystemException;
import com.citi.dahg.cve.controller.model.Usuario;
import com.citi.dahg.cve.controller.service.local.UserService;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author dh90940
 */
@ManagedBean
@ViewScoped
public class LoginBean extends BasicManagedBean {
    
    @EJB
    private UserService service;
    @ManagedProperty("#{usuarioBean}")
    private UsuarioBean usuarioBean;
    private String soeid;
    private String pass;
    
    public String login() {        
        try {
            if (soeid==null || soeid.isEmpty())
                throw new SystemException("Ingrese soeid");
            if (pass==null || pass.isEmpty())
                throw new SystemException("Ingrese password");
            
            Usuario usuario = service.login(soeid, pass);
            usuarioBean.setCurrent(usuario);
            addInfo("Usuario ingresado");
            return "principal";
        } catch (SystemException ex) {
            addError(ex.getMessage());
        }
        return null;
    }

    public String getSoeid() {
        return soeid;
    }

    public void setSoeid(String soeid) {
        this.soeid = soeid;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public void setUsuarioBean(UsuarioBean usuarioBean) {
        this.usuarioBean = usuarioBean;
    }
    
    
    
    
}
